package my.hnb.android.model;

import java.util.Vector;

import my.hnb.android.common.ActionEvent;
import my.hnb.android.common.ServerPath;
import my.hnb.android.constant.Constants;
import my.hnb.android.network.HTTPListenner;
import my.hnb.android.network.HTTPMessage;
import my.hnb.android.network.HTTPRequest;
import my.hnb.android.network.HTTPResponse;
import my.hnb.android.network.HttpAsyncTask;
import my.hnb.android.network.NetworkUtil;

public abstract class AbstractModelService implements HTTPListenner{

	public void onReceiveError(HTTPResponse response) {
		// TODO Auto-generated method stub
		
	}

	public void onReceiveData(HTTPMessage mes) {
		// TODO Auto-generated method stub
		
	}
	
	
	@SuppressWarnings("rawtypes")
	protected HTTPRequest sendHttpRequest(String method, Vector data, ActionEvent actionEvent) {
		StringBuffer strBuffer = new StringBuffer();
		strBuffer.append(NetworkUtil.getJSONString(method, data));
		HTTPRequest re = new HTTPRequest();
		re.setUrl(ServerPath.SERVER_PATH);		
		re.setAction(actionEvent.action);
		re.setContentType(HTTPMessage.CONTENT_JSON);
		re.setMethod(Constants.HTTPCONNECTION_POST);
		re.setDataText(strBuffer.toString());
		re.setObserver(this);
		re.setUserData(actionEvent);
		new HttpAsyncTask(re).execute();
		return re;
	}
	
}

